//
//  main.m
//  Memory4
//
//  Created by cora1n on 14-8-11.
//  Copyright (c) 2014年 devwu. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "Person.h"
//集合对象的内存管理
int main(int argc, const char * argv[])
{
    
    for (int i = 0; i<100000; i++) {
        Person * p1 = [[Person alloc]init];
        NSString * name = [[NSString alloc]initWithFormat:@"zhangsan"];
        p1.name = name;
        [name release];
        //当对象的引用计数为0时,dealloc 方法被调用
        //在dealloc中应该对其拥有的所有成员对象进行 release操作,防止内存泄露
        [p1 release];
    }
    
    
    
    
//    
//    Person * p2 = [[Person alloc]init];
//    p2.name = @"lisi";
//    NSLog(@"p1.retainCount = %lu",p1.retainCount);
//    NSLog(@"p2.retainCount = %lu",p2.retainCount);
//    
////    NSMutableArray * mArr1 = [[NSMutableArray alloc]init];
//    NSMutableDictionary * mDIc1 = [[NSMutableDictionary alloc]init];
//    //当对象被添加到集合对象中时,该对象的引用计数+1 ( retain )
//    [mDIc1 setObject:p1 forKey:@"p1"];
//    [mDIc1 setObject:p2 forKey:@"p2"];
//    
////    [mArr1 addObject:p1];
////    [mArr1 addObject:p2];
//    //当对象从集合中移除时,该对象的引用计数-1 ( release )
//    
//    [mDIc1 removeObjectForKey:@"p1"];
//    //当集合对象释放时,集合中的所有成员的均会执行release方法
////    [mArr1 release];
////    [mDIc1 release];
//    
//    
//    NSLog(@"p1.retainCount = %lu",p1.retainCount);
//    NSLog(@"p2.retainCount = %lu",p2.retainCount);
    
    
    
    return 0;
}

